package com.gupaoedu.baifc.dynamicproxy.jdkproxy;

import com.gupaoedu.baifc.Person;
import org.omg.CORBA.SystemException;
import org.omg.CORBA.portable.InputStream;
import org.omg.CORBA.portable.InvokeHandler;
import org.omg.CORBA.portable.OutputStream;
import org.omg.CORBA.portable.ResponseHandler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * projectName: baifc_proxy
 * packageName: com.gupaoedu.baifc.dynamicproxy.jdkproxy
 * Created: 2019/3/18.
 * Auther: baifc
 * Description:
 */
public class JDKMeipo implements InvocationHandler {


    private Person target;

    public Object getInstance(Person target) {
        this.target = target;

        Class clazz = target.getClass();

        return Proxy.newProxyInstance(clazz.getClassLoader(), clazz.getInterfaces(), this);
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object obj = method.invoke(target, args);
        after();
        return obj;
    }


    private void before() {
        System.out.println("开始物色...");
    }

    private void after() {
        System.out.println("物色OK");
    }
}
